import { Controller, Post, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ObjectId } from 'bson';
import { setWxConfigReqDto } from './dto/set-config.dto';
import { WxService } from './wx.service';

@ApiTags('wx-config')
@Controller('wx')
export class WxController {
  constructor(private readonly wxService: WxService) {}
  @Post('config/item')
  async createConfig(@Query() query: setWxConfigReqDto) {
    const { appid, secret, template_id } = query;
    await this.wxService.createConfig(appid, secret, template_id);
  }

  @Post('test/message')
  async send() {
    const openid = 'omHTU5B57QeOPTFleWfsaLk37KTI';
    const awardId = new ObjectId();
    await this.wxService.subscribeMessage(
      openid,
      awardId.toHexString(),
      '学习代码',
      Date.now(),
      '45分钟',
    );
  }
}
